#include "dialog1.h"
#include "ui_dialog1.h"
#include <QString>
#include <QtSql>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QMessageBox>
Dialog1::Dialog1(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog1)
{
    ui->setupUi(this);
}

Dialog1::~Dialog1()
{
    delete ui;
}

//用户注册处理函数
int Dialog1::on_pushButton_clicked()
{
    QString name=ui->lineEdit->text();
    QString password=ui->lineEdit_2->text();
    QSqlDatabase db;
     db = QSqlDatabase::database("conn");
     QSqlQuery query(db);
    if(name == "" ||password == ""){
            QMessageBox::information(this,"警告","输入不能为空",QMessageBox::Ok);
     }
    else{
     query.prepare("select usr_name from user where usr_name=:username");
     query.bindValue(":username",name);
     query.exec();

     if(query.next())
     {
          QMessageBox::information(this,"警告","用户名已存在！",QMessageBox::Ok);
     }
     else{
       query.prepare("insert into usr_info(usr_name,passwd)"
                  "values(:usr_name,:passwd)");
       query.bindValue(":usr_name", name);
       query.bindValue(":passwd",password);
       bool d=query.exec();
       QMessageBox msgBox;
       if(d){
          msgBox.setText("注册成功.");
           msgBox.exec();
       }
    accept();
         
     }
    }
}


